﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ManagerServices.Constants;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Common;
using System.Data.Common;
using ManagerServices.Entity;
using System.Data;
using System.Linq;
namespace ManagerServices.Data
{
    public class ProfileData
    {

        private static ProfileData instance = null;

        public static ProfileData Instance
        {
            get
            {
                if (instance == null)
                    instance = new ProfileData();

                return instance;
            }

        }

        public Int32 Createprofile(ProfileEntity profileinfo)
        {


            //string sqlCommand = "SELECT TOP 5 FirstName, LastName, JobTitle FROM HumanResources.vEmployee"; 
            //_database.GetSqlStringCommand(sqlCommand); Dbconfig.Instance.Setting()
            Int32 newProfileID = 0;
            Database _database = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = _database.GetStoredProcCommand("sp_add_profile");
            try
            {

                _database.AddInParameter(dbCommand, "@NAME", System.Data.DbType.String, profileinfo.NAME);
                _database.AddInParameter(dbCommand, "@FULLNAME", System.Data.DbType.String, profileinfo.FULLNAME);
                _database.AddInParameter(dbCommand, "@DIRTHDAY", System.Data.DbType.DateTime, profileinfo.DIRTHDAY);
                _database.AddInParameter(dbCommand, "@GENDER", System.Data.DbType.String, profileinfo.GENDER);
                _database.AddInParameter(dbCommand, "@DATECREATE", System.Data.DbType.DateTime, profileinfo.DATECREATE);

                

                //filasEfectadas = dbCommand.ExecuteDataSet(dbCommand);

                newProfileID = (Int32)_database.ExecuteScalar(dbCommand);
               

            }
            catch (Exception e)
            {
                return e.Data.Count;
               // filasEfectadas = null;

            }
            finally
            {
                dbCommand.Dispose();

            }


            return newProfileID;

        }  
        
    }
}